<!--用户管理-->
<template>
  <div class="page-container">
    <ex_super_table_page v-bind="option" ref="superTablePage">
    </ex_super_table_page>

    <el-dialog :title="dialogTitle" :visible.sync="dialogFormVisible" width="540px" :close-on-click-modal="false">
      <el-form ref="formEl" :model="formValue" :rules="rules" label-width="120px" class="common-form-panel-div"
               style="padding: 0px 10px; margin-top: 10px; ">

        <el-row>
          <el-col>
            <el-form-item label="业务线名称" prop="buName">
              <el-input v-model="formValue.buName"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col>
            <el-form-item label="业务线编码" prop="buCode">
              <el-input v-model="formValue.buCode"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col>
            <el-form-item label="备注">
              <el-input v-model="formValue.remark"></el-input>
            </el-form-item>
          </el-col>
        </el-row>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">{{ $tt('label_fms_account_config_cancel') }}</el-button>
        <el-button type="primary" @click="submitForm">{{ $tt('label_fms_account_config_confirm') }}</el-button>
      </div>
    </el-dialog>


  </div>
</template>
<script>

  let moduleName = "label_fms_service_code_expense_item_manage"
  import superTablePageFunction from '@/mixin/super-table-page-function';

  export default {

    mixins: [superTablePageFunction],
    title: '业务线管理',
    components: {},

    data() {

      let _this = this

      return {
        dialogFormVisible: false,
        dialogTitle: '',
        formValue: {},
        rules: {
          buName: [
            {required: true, message: '请输入业务线名称', trigger: 'blur'},
          ],
          buCode: [
            {required: true, message: '请输入业务线编码', trigger: 'blur'},
          ]
        },

        subjectArr: [],
        subjectMap: {}

      };
    },

    watch: {
      'formValue.companyId'(val, old) {

      }
    },

    created() {

      let _this = this

      _this.option = {
        search: {
          model: [
            { label: "label_fms_bank_card_keyword", key: "keyword", },
            {
              label: "label_fms_account_apply_status", key: "status", type: 'select', enum: 'IsAvailableStatusEnum', attrs: { clearable: true }
            }
          ],
        },
        action: [
          {
            label: '新增业务线', auth:'fms_config_service_code_edit', attrs: { icon: "el-icon-plus" }, click: () => {
              this.dialogTitle = '新增业务线'
              this.dialogFormVisible = true
              this.formValue = {}
            }
          },
        ],

        table: {
          url: "/ums-api/user/UserCompanyBuRpc/selectAll.json",
          attrs: {
            'cell-style': ({ row, column, rowIndex, columnIndex }) => {
              if (column.property == 'status') {
                return { color: row.status == 'NORMAL' ? this.$globalCss.successColor : this.$globalCss.infoColor }
              }
            }
          },
          model: [

            {key: 'buName', label: '业务线名称', align: 'left', minWidth: 100},
            {key: 'buCode', label: '业务线编码', align: 'left', minWidth: 100},
            {
              key: 'status', label: 'label_fms_account_apply_status',
              minWidth: 100,
              attrs: {
                formatter: (r, c, v, i) => {
                  return this.$enumShow(v, 'IsAvailableStatusEnum')
                }
              }
            },
            {key: 'remark', label: '备注', align: 'left', minWidth: 100},
            {
              type: 'operate', minWidth: 100,
              operate: [

                {
                  label: 'IsAvailableStatusEnum__DISABLED',
                  // auth:'fms_config_service_code_disable',
                  type: "confirm-button",
                  message: "label_fms_bank_card_confirm_forbidden",
                  url: '/ums-api/user/UserCompanyBuRpc/disable.json',
                  if: (row) => {
                    return row.status == 'ENABLE'
                  },
                  params: (v) => {
                    return { id: v.id }
                  },
                  done: ['reload', 'tip'],
                },
                {
                  label: 'IsAvailableStatusEnum__ENABLE',
                  // auth:'fms_config_service_code_disable',
                  type: "confirm-button",
                  message: "label_fms_bank_card_confirm_enable",
                  url: '/ums-api/user/UserCompanyBuRpc/enable.json',
                  if: (row) => {
                    return row.status != 'ENABLE'
                  },
                  params: (v) => {
                    return { id: v.id }
                  },
                  done: ['reload', 'tip']
                },
                {
                  label: 'label_edit',
                  // auth:'fms_config_service_code_edit',
                  click: (row) => {
                    this.dialogTitle = '修改业务线'
                    this.formValue = JSON.parse(JSON.stringify(row))
                    this.dialogFormVisible = true
                  }
                },
                {
                  label: 'label_delete',
                  // auth:'fms_config_service_code_delete',
                  type: "confirm-button",
                  url: '/ums-api/user/UserCompanyBuRpc/remove.json',
                  if: (row) => {
                    return row.status != 'ENABLE'
                  },
                  message: 'label_fms_bank_card_confirm_delete',
                  params: (v) => {
                    return { id: v.id }
                  },
                  done: ['reload', 'tip']
                }
              ],
            }
          ]
        }
      }


    },

    props: {},

    destroyed() {

    },

    methods: {

      submitForm() {

        let _this = this

        _this.$refs['formEl'].validate((valid) => {
          if (valid) {

            _this.$ajax({
              url: '/ums-api/user/UserCompanyBuRpc/saveUpdate.json',
              type: 'json',
              data: _this.formValue,
              success: (responseData) => {
                this.$message({
                  showClose: true,
                  message: '提交成功',
                  type: 'success'
                })
                _this.$refs['superTablePage'].reload()
                _this.dialogFormVisible = false
              }
            });

          } else {
            return false;
          }

        });

      }


    }
  };

</script>

